package cn.wgx.module.mind.web;

import cn.wgx.common.base.IBaseController;
import cn.wgx.common.entity.mind.ProjectUser;
import cn.wgx.common.entity.sys.SysUser;
import cn.wgx.common.util.ResponseDataUtil;
import cn.wgx.module.mind.service.ProjectUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "01.2 项目人员")
@RestController
@RefreshScope
@RequestMapping("/api/mind/projectUser")
public class ProjectUserCtrl extends IBaseController<ProjectUserService, ProjectUser> {


    @ApiOperation(value = "根据实体参数查询列表,分页查询(page第几页, limit每页数量,默认20)")
    @GetMapping("list")
    public Map list(@ModelAttribute ProjectUser project,
                    @RequestParam(required = false, defaultValue = "1") Integer page,
                    @RequestParam(required = false, defaultValue = "20") Integer limit) {
        Page page1 = new Page(page, limit);
        return ResponseDataUtil.returnData(page1, service.getProUsers(page1, new QueryWrapper<>(project), project.getNickname()));
    }



    //todo 需修改,获取列表为本企业人员
    @ApiOperation(value = "查询未加入项目的企业人员,分页查询(page第几页, limit每页数量,默认20)")
    @GetMapping("listUserNotInProject")
    public Map listUserNotInProject(@RequestParam Integer pro_id,
                                    @RequestParam(required = false) String nickname,
                    @RequestParam(required = false, defaultValue = "1") Integer page,
                    @RequestParam(required = false, defaultValue = "20") Integer limit) {
        Page<SysUser> page1 = new Page(page, limit);
        return ResponseDataUtil.returnData(page1, service.getUserListNotInProject(page1, pro_id,nickname));
    }

    @ApiOperation(value = "根据项目ID和用户ID修改数据, 可以修改角色ID")
    @PatchMapping("updateByProId")
    public Map updateByProIdAndUserId(@RequestBody ProjectUser projectUser, @RequestParam(required = false) String access_token) {

        return ResponseDataUtil.returnData(service.updateByProId(projectUser));
    }
    @ApiOperation(value = "根据项目ID用户ID删除数据")
    @DeleteMapping("del/{pro_id}/{user_id}")
    public Map del(@PathVariable Integer pro_id,@PathVariable Integer user_id, @RequestParam(required = false) String access_token) {
        ProjectUser project = new ProjectUser();
        project.setPro_id(pro_id);
        project.setUser_id(user_id);
        return ResponseDataUtil.returnData(service.remove(new QueryWrapper<>(project)));
    }

}
